package com.primaryedu.ui;

import com.primaryedu.R;
import com.primaryedu.data.GlobalData;
import com.primaryedu.ui.app.classadjust.ClassAdjustActivity;
import com.primaryedu.ui.app.leave.LeaveListActivity;
import com.primaryedu.ui.app.parentsch.LookingforparentsActivity;
import com.primaryedu.ui.app.messageboard.MessageboardActivity;
import com.primaryedu.ui.app.parentsch.ParentSchoolActivity;
import com.primaryedu.ui.exercise.ExerciseActivity;
import com.primaryedu.ui.repair.MyRepairActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ScrollView;
import android.widget.TextView;

/***
 * 应用中心
 * @description
 * @data 2017年11月29日

 * @author jun.wang
 */
public class AppCenterActivity extends BaseActivity implements OnClickListener {
    private TextView textOne, textTwo;
    private TextView textThree, textFour;
    private String tag = "";
    private ScrollView scrollView;
    private Handler handler = new Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_app_center);
        tag = getIntent().getStringExtra("tag");
        init();
    }

    private void init() {
        ((TextView) findViewById(R.id.title)).setText("校园应用中心");
        $(R.id.back).setOnClickListener(this);
        $(R.id.layoutOne).setOnClickListener(this);
        $(R.id.layoutTwo).setOnClickListener(this);
        $(R.id.layoutThree).setOnClickListener(this);
        $(R.id.layoutFour).setOnClickListener(this);
        $(R.id.layoutFive).setOnClickListener(this);
        $(R.id.layoutSix).setOnClickListener(this);
        $(R.id.layoutSeven).setOnClickListener(this);
        $(R.id.layoutEight).setOnClickListener(this);
        $(R.id.layoutNine).setOnClickListener(this);
        $(R.id.layoutTen).setOnClickListener(this);
        $(R.id.layouteleven).setOnClickListener(this);
        $(R.id.layoutTwelve).setOnClickListener(this);

        Animation out = AnimationUtils.loadAnimation(AppCenterActivity.this, R.anim.push_left_in);

        textOne = (TextView) this.$(R.id.textOne);
        textTwo = (TextView) this.$(R.id.textTwo);
        textThree = (TextView) this.$(R.id.textThree);
        textFour = (TextView) this.$(R.id.textFour);
        scrollView = (ScrollView) this.$(R.id.scrollView);

        if (tag.equals("1")) {
            textOne.startAnimation(out);
        } else if (tag.equals("2")) {
            textTwo.startAnimation(out);
        } else if (tag.equals("3")) {
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    scrollView.fullScroll(ScrollView.FOCUS_DOWN);
                }
            }, 300);

            textThree.startAnimation(out);
        } else {
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    scrollView.fullScroll(ScrollView.FOCUS_DOWN);
                }
            }, 300);

            textFour.startAnimation(out);
        }

    }

    @Override
    protected int BindLayout() {
        return R.layout.activity_app_center;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

    @Override
    public void onClick(View v) {
        Intent intent = null;

        switch (v.getId()) {
            case R.id.back:
                finish();
                break;

            case R.id.layoutOne:
                intent = new Intent(AppCenterActivity.this, ExerciseActivity.class);
                intent.putExtra("columnId", "eef4acaf63ba47b48ce89bb5d5e07e50");
                intent.putExtra("titleStr", "美丽校园");
                startActivity(intent);
                break;

            case R.id.layoutTwo:
                intent = new Intent(AppCenterActivity.this, ExerciseActivity.class);
                intent.putExtra("columnId", "f765c7c6f33648a1b4a476e8f0531b6a");
                intent.putExtra("titleStr", "缤纷社团");
                startActivity(intent);
                break;

            case R.id.layoutThree:
                intent = new Intent(AppCenterActivity.this, ExerciseActivity.class);
                intent.putExtra("columnId", "9c7b751edb994450bcdd538458431f91");
                intent.putExtra("titleStr", "教育资源");
                startActivity(intent);
                break;

            case R.id.layoutFour:
                intent = new Intent(AppCenterActivity.this, ExerciseActivity.class);
                intent.putExtra("columnId", "90b528424147472e88467f0c03b42dd0");
                intent.putExtra("titleStr", "安全教育");
                startActivity(intent);
                break;

            case R.id.layoutFive://课务调整
                //			 showToast("暂未开通，敬请期待！");
                if (GlobalData.getUsertype(getApplicationContext()).contains("3")
                        || GlobalData.getUsertype(getApplicationContext()).contains("4")) {
                    showToast("当前角色不可使用！");
                } else {
                    intent = new Intent(AppCenterActivity.this, ClassAdjustActivity.class);
                    startActivity(intent);
                }
                break;

            case R.id.layoutSix://报修
                if (GlobalData.getUsertype(getApplicationContext()).contains("3")
                        || GlobalData.getUsertype(getApplicationContext()).contains("4")) {
                    showToast("当前角色不可使用！");
                } else {
                    intent = new Intent(AppCenterActivity.this, MyRepairActivity.class);
                    intent.putExtra("title", "报修列表");
                    startActivity(intent);
                }
                break;

            case R.id.layoutSeven://请假
                //			 showToast("暂未开通，敬请期待！");
                if (GlobalData.getUsertype(getApplicationContext()).contains("2")
                        || GlobalData.getUsertype(getApplicationContext()).contains("5")
                        || GlobalData.getUsertype(getApplicationContext()).contains("7")
                        || GlobalData.getUsertype(getApplicationContext()).contains("8")) {//2：老师 5：班主任 7：校长  8：请假管理员
                    intent = new Intent(AppCenterActivity.this, LeaveListActivity.class);
                    startActivity(intent);
                } else {
                    showToast("当前角色不可使用！");
                }
                break;

            case R.id.layoutEight://家长学校
                if (GlobalData.getUsertype(getApplicationContext()).contains("3")
                        || GlobalData.getUsertype(getApplicationContext()).contains("4")
                        || GlobalData.getUsertype(getApplicationContext()).contains("7")) {
                    intent = new Intent(AppCenterActivity.this, ParentSchoolActivity.class);
                    startActivity(intent);
                } else {
                    showToast("当前角色不可使用！");
                }
                break;

            case R.id.layoutNine://校长信箱
                			 showToast("正在开发，敬请期待！");
              /*  if (GlobalData.getUsertype(getApplicationContext()).contains("7")) {//管理员
                    jumpTo(BoxListActivity.class);//查看校长信箱
                } else {//普通用户
//                    intent = new Intent(AppCenterActivity.this, BoxWriteActivity.class);//校长信箱
//                    startActivity(intent);
                    jumpTo(BoxWriteActivity.class);//给校长写信
                }*/
                break;
            case R.id.layoutTen://学生请假
               /* if (GlobalData.getUsertype(getApplicationContext()).contains("3")
                        || GlobalData.getUsertype(getApplicationContext()).contains("4")
                        || GlobalData.getUsertype(getApplicationContext()).contains("5")
                        || GlobalData.getUsertype(getApplicationContext()).contains("7")) {//学生，家长，班主任，校长
                    intent = new Intent(AppCenterActivity.this, StudentLeaveListActivity.class);
                    startActivity(intent);
                } else {
                    showToast("当前角色不可使用！");
                }*/
                showToast("正在开发，敬请期待！");
                break;
            case R.id.layouteleven:
//                intent = new Intent(AppCenterActivity.this, LookingforparentsActivity.class);
//                intent.putExtra("urlStr", "http://njtx.njtxqxx.com/static/default/zjz.html");
//                startActivity(intent);
                Bundle bundle = new Bundle();
                bundle.putString("urlStr", "http://njtx.njtxqxx.com/static/default/zjz.html");
                jumpbundleTo(LookingforparentsActivity.class,bundle);
                break;
            case R.id.layoutTwelve://留言发布
//                intent = new Intent(AppCenterActivity.this, MessageboardActivity.class);
//                startActivity(intent);
                jumpTo(MessageboardActivity.class);
                break;
            default:
                break;
        }
    }


}
